const router = require('koa-router')()
const { models, sequelize } = require('../../utils/db')
const { resBody } = require('../../utils/index')

router.post('/getSpecialList', async(ctx) => {
    let {ps = 10, pn = 1, id} = ctx.request.body;
    let condition = {
        categoryId: id
    };
    let data = await models.special_model.findAll({
        raw: true,
        where: condition,
        attributes: ['sid', 'title', 'categoryId', 'tagId'],
        limit: ps,
        offset: (pn - 1) * ps
    });
    let count = await models.special_model.count({
        where: condition
    });
    let maxPage = Math.ceil(count / ps)
    ctx.body = {
        ...resBody.success,
        data,
        count,
        maxPage
    };
});

module.exports = router